/*--------------------------+
|	   Emitter Class		|
|	---------------------	|
|	Emitter contain and		|
|	emit Particles, also	|
|	managing their data		|
|		and memory.			|
+--------------------------*/

#pragma once

#include <vector>
#include "SGD Wrappers\SGD_Math.h"
#include "SGD Wrappers\CSGD_Direct3D.h"

// I'm lazy
#define uint unsigned int

class Particle;

class Emitter {

private:
	// The particle all other particles will be created from
	Particle* MasterParticle;

	// All of this emitter's particles
	std::vector<Particle*> Particles;

	// The shape of the emitter
	int Shape;

	// The position of the emitter
	tVector2D Position;

	// Control whether the emitter bursts or loops
	bool Looping;

	// Control emission speed
	float EmissionDelay;
	float EmissionTimer;
	uint EmissionRate;

	// Control number of particles used by the emitter
	uint MaxParticles;
	uint MinParticles;

	// The range to randomize
	float LifetimeRange;
	float ScaleRange;
	float XRange;
	float YRange;
	float VelocityRange;
	float RotationRange;
	float RotationSpeedRange;

	bool Bursting;
	uint BurstSize;

public:
	// Constructor
	Emitter(int shape, tVector2D pos, Particle* master, uint min, uint max, float liferange = 0, float scalerange = 0, float xrange = 0, float yrange = 0, float velrange = 0, float rotrange = 0, float rotspeedrange = 0, float emissiondelay = 0, uint emissionrate = 1);

	// Render all of the emitters particles
	void Render() const;

	// Update emitter and all of it's particles
	void Update(float elapsedTime);

	// Activate the emitter
	void Burst(void);

	// Set the emitter to loop
	inline void Loop(bool loop = true) { Looping = loop; }

	// Accessors
	inline bool IsLooping(void) { return Looping; }

	// Shutdown
	void Shutdown(void);

	// Set the Position
	void SetPosition(float x, float y);

	// Load an emitter from a file
	static Emitter* LoadEmitter(const char* filename);
};
